<?php
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 15-11-13
 * Time: 上午11:29
 */
$tmp =  array (
    'sid' => '42232',
    'memberID' => '42232',
    'account' => '124517',
    'dtype' => '0',
    'dname' => '安徽秋浦河旅游股份有限公司',
);
echo base64_encode(json_encode($tmp));
//eyJpZCI6IjQyMjMyIiwiYWNjb3VudCI6IjEyNDUxNyIsImR0eXBlIjoiMCIsImRuYW1lIjoiXHU1Yjg5XHU1ZmJkXHU3OWNiXHU2ZDY2XHU2Y2IzXHU2NWM1XHU2ZTM4XHU4MGExXHU0ZWZkXHU2NzA5XHU5NjUwXHU1MTZjXHU1M2Y4In0=
exit;
$str = '4,242,294,679,973,1079,1126,1214,1313,1928,1929,2115,2386,2445,2449,2487,3001,3436,3748,4196,4252,4274,4453,4615,4652,4782,4868,4981,5134,5135,6216,6225,6262,6271,6502,6578,6772,7099,7187,7328,7435,7492,7508,7589,12765,20502,20894,21105,21268,21564,22411,22423,22610,22647,22845,22863,23008,23265,23577,23938,23953,24016,24161,24287,24437,24619,24705,24863,24975,25119,25590,25875,26023,26153,26232,26233,26355,26524,26557,26568,26640,26697,26781,26855,26983,27126,27146,27203,27205,27271,27283,27309,27319,27565,27584,27585,27778,27935,28149,28217,28397,28689,28790,29060,29525,29556,29697,29734,35156,35173,35225,35275,35631,35666,36188,36333,36624,36710,36836,36949,36952,37052,37393,37408,37459,37758,37809,37928,38154,38343,38385,38399,38664,38717,38748,38783,38955,39002,39177,39266,39267,39304,39430,39499,39659,39828,39940,40101,40142,40210,40606,40733,40746,41551,42119,42232,42586,42854,42894,43094,43396,43517,44422,44489,44688,44773,45133,45461,45602,45695,45814,46167,46460,46575,46638,46870,46964,47029,47161,47870,48136,48142,48760,49283,49398,49495,49812,50039,50044,50066,50327,50404,50512,50618,50867,51120,51521,51594,51715,51740,51758,51800,52034,52067,52116,52147,52308,52318,53085,53131,53166,53185,54026,54163,55729,55886,56217,56294,56410,56449,56540,56592,56683,56766,56869,56957,57111,57263,57270,57302,57565,57648,57772,57801,57909,57976,58205,58313,58370,58605,58776,59196,59238';
$arr = explode(',', $str);
echo count($arr),"\n";
$t10 = array_splice($arr,0, 10);
echo "\n",'====10 people====',"\n";
var_export($t10);

$t50 = array_splice($arr,0, 50);
echo "\n",'====50 people=====',"\n";
var_export($t50);
$t100 = array_splice($arr, 0, 100);
echo "\n",'====100 people=====',"\n";
var_export($t100);


echo count($t50),"\n";
echo count($arr),"\n";

//print_r($arr);

exit;
$request_arr = [];
for($i=100;$i<1000;$i++)  {
    $request_arr[] = "http://192.168.1.205/log.php?req={$i}";
}
//$request_arr = array(
//    'http://192.168.1.205/log.php?req=22212',
//    'http://www.jd.com',
//    'http://www.taobao.com',
//    'http://www.qq.com',
//);
async_get_url($request_arr);
echo 'ok';
function async_get_url($url_array, $wait_usec = 0)
{
    if (!is_array($url_array))
        return false;
    $wait_usec = intval($wait_usec);
    $data    = array();
    $handle  = array();
    $running = 0;
    $mh = curl_multi_init(); // multi curl handler
    $i = 0;
    foreach($url_array as $url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return don't print
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 302 redirect
        curl_setopt($ch, CURLOPT_MAXREDIRS, 7);
        curl_multi_add_handle($mh, $ch); // 把 curl resource 放进 multi curl handler 里
        $handle[$i++] = $ch;
    }
    /* 执行 */
    do {
        curl_multi_exec($mh, $running);
        if ($wait_usec > 0) /* 每个 connect 要间隔多久 */
            usleep($wait_usec); // 250000 = 0.25 sec
    } while ($running > 0);
    /* 读取资料 */
    foreach($handle as $i => $ch) {
        $content  = curl_multi_getcontent($ch);
        $data[$i] = (curl_errno($ch) == 0) ? $content : false;
    }
    /* 移除 handle*/
    foreach($handle as $ch) {
        curl_multi_remove_handle($mh, $ch);
    }
    curl_multi_close($mh);
    return $data;
}